/*
Clean EU-SILC cross-sectional household data (H-file), 2004-2023.
Extracts household-level variables for each year and appends into
a single panel.

Uses:
$usern/Raw_Data/NO_CROSS/[year]/UDB_cNO[yy]H.csv  (years 2004-2023)

Creates:
$usern/Intermediate_Data/[year]_H_vars.dta  (years 2004-2023)
$usern/Intermediate_Data/0423_H_vars.dta
*/

*** Set directory
clear
global usern "$root/data/silc"

********************************************************************************
*** HOUSEHOLD DATA (H-FILE)
********************************************************************************

forv year=2004(1)2023 {
	local y = substr("`year'", -2, .) // Extract the last two digits of the year
	display "`y'"
	display "`year'"
	
	import delimited "$usern/Raw_Data/NO_CROSS/`year'/UDB_cNO`y'H.csv", varnames(1) clear
	
	rename hb010 year
	label var year "Year of the survey"

	rename hb030 hhid
	tostring hhid, replace 
	label var hhid "Household ID (persid without last 2 digits)"
	
	rename hy050g child_allowance
	label var child_allowance "Family/Child-related allowances"
	
	keep year hhid child_allowance
	
	save "$usern/Intermediate_Data/`year'_H_vars.dta", replace
}


*** Append years
use "$usern/Intermediate_Data/2004_H_vars.dta", clear

forv year=2005(1)2023 {
	append using "$usern/Intermediate_Data/`year'_H_vars.dta", force
}
save "$usern/Intermediate_Data/0423_H_vars.dta", replace
